package com.doctor.windflower_doctor.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;



import com.doctor.windflower_doctor.R;
import com.doctor.windflower_doctor.entity.BloodPressureBeen;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BloodPressureAdapter extends BaseAdapter {
	private Context context;
	private List<BloodPressureBeen> list;
	private LayoutInflater inflater;

	public BloodPressureAdapter(Context context) {
		this.context = context;
		list = new ArrayList<BloodPressureBeen>();
	}

	public void addList(List<BloodPressureBeen> list) {
		this.list.addAll(list);
		this.inflater = LayoutInflater.from(context);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_display, null);
			holder.time_text = (TextView) convertView
					.findViewById(R.id.time_text);
			holder.value_text = (TextView) convertView
					.findViewById(R.id.value_text);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.time_text.setText(getTime(Long.valueOf(list.get(position).getCreatedAt())));
		holder.value_text.setText(list.get(position).getBloodPressure()+"mmHg");
		return convertView;
	}

	class ViewHolder {
		TextView time_text;
		TextView value_text;
	}

	@SuppressLint("SimpleDateFormat")
	String getTime(Long timeStr) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date(timeStr);
		return dateFormat.format(date);
	}
}
